//
//  GYMineProductInfoDetailViewModel.m
//  GYDemo
//
//  Created by mac on 2018/3/30.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYMineProductInfoDetailViewModel.h"
#import "GYMineProductInfoEditViewModel.h"
#import "Head.h"

@implementation GYMineProductInfoDetailHeadViewModel
@end

@implementation GYMineProductInfoDetailModel

+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
             @"address" : @"saleProduct.address",
             @"area" : @"saleProduct.area",
             @"city" : @"saleProduct.city",
             @"companyname" : @"saleProduct.companyname",
             @"count":@"saleProduct.count",
             @"createtime":@"saleProduct.createtime",
             @"descriptionField":@"saleProduct.description",
             @"down":@"saleProduct.down",
             @"idField":@"saleProduct.id",
             @"imgUrl":@"saleProduct.imgUrl",
             @"linkmobile":@"saleProduct.linkmobile",
             @"name":@"saleProduct.name",
             @"pid":@"saleProduct.pid",
             @"price":@"saleProduct.price",
             @"protypeid":@"saleProduct.protypeid",
             @"protypename":@"saleProduct.protypename",
             @"province":@"saleProduct.province",
             @"qq":@"saleProduct.qq",
             @"salecount":@"saleProduct.salecount",
             @"saleid":@"saleProduct.saleid",
             @"score":@"saleProduct.score",
             @"setnum":@"saleProduct.setnum",
             @"status":@"saleProduct.status",
             @"topid":@"saleProduct.topid",
             @"unit":@"saleProduct.unit",
             @"username":@"saleProduct.username",
             @"propertyList":@"propertyList",
             @"userInfo":@"userInfo"
             };
}

@end


@interface GYMineProductInfoDetailViewModel()
@property (nonatomic,strong) NSMutableArray *items1;
@end
@implementation GYMineProductInfoDetailViewModel
#pragma mark - getter and setter
-(GYMineProductInfoDetailHeadViewModel *)productInfoDetailHeadViewModel
{
    if (!_productInfoDetailHeadViewModel) {
        _productInfoDetailHeadViewModel = [GYMineProductInfoDetailHeadViewModel new];
    }
    return _productInfoDetailHeadViewModel;
}
-(NSMutableArray *)items1
{
    if (!_items1) {
        _items1 = [NSMutableArray new];
    }
    [_items1 removeAllObjects];
    for (NSDictionary *dic in self.productInfoDetailModel.propertyList) {
        NSString *propertyname = dic[@"name"] ?: @"";
        NSString *propertyvalue = dic[@"propertyvalue"] ?: @"";
        GYMineProductInfoEditDetailCellModel *model = [GYMineProductInfoEditDetailCellModel new];
        model.cellHeight = WFCGFloatY(45);
        model.title = propertyname;
        model.value = propertyvalue;
        model.action = @"";
        [_items1 addObject:model];
    }
    if (self.productInfoDetailModel.descriptionField.length > 0) {
        GYMineProductInfoEditDetailCellModel *model = [GYMineProductInfoEditDetailCellModel new];
        model.cellHeight = WFCGFloatY(224.5);
        model.value = self.productInfoDetailModel.descriptionField;
        model.isEditable = NO;
        model.isExpandable = YES;
        model.action = @"";
        [_items1 addObject:model];
    }
    return _items1;
}
-(NSMutableArray *)allItems
{
    if (!_allItems) {
        _allItems = [NSMutableArray new];
    }
    [_allItems removeAllObjects];
    [_allItems addObject:self.items1];
    return _allItems;
}
-(void)setProductInfoDetailModel:(GYMineProductInfoDetailModel *)productInfoDetailModel
{
    _productInfoDetailModel = productInfoDetailModel;
    self.productInfoDetailHeadViewModel.imgUrl = _productInfoDetailModel.imgUrl;
    _productInfoDetailHeadViewModel.name = _productInfoDetailModel.name;
    _productInfoDetailHeadViewModel.type = _productInfoDetailModel.protypename;
    _productInfoDetailHeadViewModel.createtime = [NSString stringWithFormat:@"发布时间：%@",[WFFunctions WFTimeGetString:[NSDate dateWithTimeIntervalSince1970:_productInfoDetailModel.createtime / 1000] byFormatter:@"yyyy-MM-dd"]];
    _productInfoDetailHeadViewModel.unit = _productInfoDetailModel.unit;
    _productInfoDetailHeadViewModel.price = [NSString stringWithFormat:@"%.2ld",(long)_productInfoDetailModel.price];
    _productInfoDetailHeadViewModel.count = [NSString stringWithFormat:@"%ld",_productInfoDetailModel.count];
    _productInfoDetailHeadViewModel.setNum = [NSString stringWithFormat:@"%ld",_productInfoDetailModel.setnum];
    _productInfoDetailHeadViewModel.saleCount = [NSString stringWithFormat:@"%ld",(long)_productInfoDetailModel.salecount];
}
#pragma mark - method
-(void)requestDetail
{
    @WeakSelf;
    NSMutableDictionary *para = [NSMutableDictionary new];
    NSString *ids = [NSString stringWithFormat:@"%ld",_productInfoModel.id];
    [para setObject:ids forKey:@"id"];
    NSString *interface = @"saleProductDetail";
    [[InterfaceManager shareInterface]requetInterface:interface withParameter:para handler:^(NSDictionary *info, InterfaceStatusModel *infoModel) {
        NSDictionary *data = infoModel.data;
        if ([data isKindOfClass:[NSDictionary class]]) {
            GYMineProductInfoDetailModel *detailModel = [GYMineProductInfoDetailModel yy_modelWithJSON:data];
            [selfp setProductInfoDetailModel:detailModel];
        }
    }];
}
@end
